const divide = (arr, start, end) => {
    let y = arr[start],
        i = start + 1,
        j = end
    while (i <= j) {
        if (arr[i] < y) {
            i++
        } else if (arr[j] >= y) {
            j--
        } else {
            let count = arr[i]
            arr[i] = arr[j]
            arr[j] = count
            i++
            j--
        }
    }
    let count = arr[start]
    arr[start] = arr[i-1]
    arr[i-1] = count
    return i - 1

}
const quick = (arr, start = 0, end = arr.length - 1) => {
    //const newArr = [...arr]
    if (end > start) {
        let pivot  = divide(arr, start, end)
        quick(arr, start, pivot  - 1)
        quick(arr, pivot  + 1, end)
    }
    return arr
    //return newArr
}

console.log(quick([2, 1, 5, 3,4,10, 9, 8, 6, 3]));
console.log(quick([10,1,2,3,4,9]));